package csdn_2;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class Test3 {
    public static void main(String[] args) {
        String path="D:\\javacode\\javacode\\IO_1\\BufRead.txt";
        String line=null;
        BufferedReader bufferedReader=null;
        try {
            bufferedReader=new BufferedReader(new FileReader(path));//包装流
            //1. bufferedReader.readLine() 是按行读取文件
            //2. 当返回null 时，表示文件读取完毕
            while((line=bufferedReader.readLine())!=null){
                System.out.println(line);
            }

        } catch (IOException e) {
            throw new RuntimeException(e);
        }finally {
            //关闭流, 这里注意，只需要关闭 BufferedReader ，因为底层会自动的去关闭节点流FileReader.
            try {
                if(bufferedReader!=null) {
                    bufferedReader.close();
                }
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
